package com.qf.zyh.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.zyh.common.ResponseResult;
import com.qf.zyh.common.ResultType;
import com.qf.zyh.dao.AppInfoMapper;
import com.qf.zyh.entity.AppInfo;
import com.qf.zyh.services.AppinfoServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppinfoServicesImpl implements AppinfoServices {
    @Autowired
    private AppInfoMapper appInfoMapper;

    @Override
    public ResultType table(Integer page, Integer limit, String corpName) {
        PageHelper.startPage(page,limit);
        System.out.println("进入2");
        List<AppInfo> list =appInfoMapper.selectByName(corpName);
        System.out.println("进入3");
        list.stream().forEach(System.out::println);
        PageInfo info = new PageInfo(list);
        return new ResultType(0,"",(int)info.getTotal(),info.getList());
    }

    @Override
    public ResponseResult delMa(Integer[] ids) {
        appInfoMapper.delMa(ids);
        return ResponseResult.getSuccess();
    }

    @Override
    public ResponseResult addMa(AppInfo a) {
        int i = appInfoMapper.insertSelective(a);
        if (i>0) {
            return ResponseResult.getSuccess();
        }
        return ResponseResult.getFail("添加出错惹");
    }

    @Override
    public ResponseResult updateMa(AppInfo a) {
        int i = appInfoMapper.updateByPrimaryKeySelective(a);
        if (i>0) {
            return ResponseResult.getSuccess();
        }
        return ResponseResult.getFail("修改出错惹");
    }
}
